﻿'''''Prachak Nov 25, 2014 10.10
Imports ADOEntityKYC
Imports System.Data
Imports System.Data.Linq.SqlClient

Partial Class KYC_IndividualSearch
    Inherits Web.UI.BasePage

#Region "Valiable"

    Dim ds As DataSet
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim clsDataTable As New clsLINQToDataTable
    Dim clsCheckID As clsCheckID
    Dim convertDate As clsDateFormat
    Dim clsCheckLanguage As clsCheckLanguage
    Dim clsDatabase As New clsDatabase
    Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
    Dim clsMasterDropDown As clsMasterDropDown
    Dim clsValid As clsValidateData

#End Region

#Region "Even Page"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        clsValid = New clsValidateData()
        Try

            btnSearch.Attributes.Add("onclick", "NoDoubleSubmit();")
            btnSearchSancList.Attributes.Add("onclick", "NoDoubleSubmit(); setAmlistParam_SEARCH(); popAMListWindow();")
            clsSessionMenuRight = Session("clsMenuRight")

            If Not IsPostBack Then
                'Me.txtNo.Text = "%"
                chkIsLogin()
                ds = New DataSet()
                resourceSet()
                CreateControlMP()
                Session("KYC") = Request.QueryString("KYC")
                Session("CUSTSEQ") = Nothing
                'If Not Request.QueryString("CUSTSEQ") = 0 Or Not Request.QueryString("CUSTSEQ") = "0" Or Not Request.QueryString("CUSTSEQ") = "" Or Not Request.QueryString("CUSTSEQ") Is Nothing Then
                '    searchAuto(CInt(Request.QueryString("CUSTSEQ")))
                'End If

                If IsNumeric(Request.QueryString("CUSTSEQ")) Then
                    If Request.QueryString("CUSTSEQ") > 0 Then
                        searchAuto(CInt(Request.QueryString("CUSTSEQ")))
                    End If
                End If

                If Request.QueryString("KYC") = 4 Then 'เรืองระดับสิทธิ์การเห็นข้อมูล
                    loadDropDown()
                    lblBranch.Visible = True
                    ddlBranch.Visible = True
                End If
            Else
                ds = Session("ds")

            End If

            VisbleKYC()

        Catch ex As Exception

            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = ds
    End Sub

#End Region


#Region "SetForm"

    Sub resourceSet()

        'lblEvidence0.Text = Resources.resSearch.CIF_TYPE
        'lblEvidence.Text = Resources.resSearch.Evidence
        'lblevIDPass.Text = Resources.resSearch.evIDPass
        'lblCustCode.Text = Resources.resSearch.CustCode
        'lblFistNameTH.Text = Resources.resSearch.AccFisstNameTH
        'lblMidNameTH.Text = Resources.resSearch.AccMidNameTH
        'lblLastNameTH.Text = Resources.resSearch.AccSurNameTH
        'lblFistNameEN.Text = Resources.resSearch.AccFisstNameEN
        'lblMidNameEN.Text = Resources.resSearch.AccMidNameEN
        'lblLastNameEN.Text = Resources.resSearch.AccSurNameEN

        'lblEvidence.Text = "เลขที่บัตรประชาชน"
        'lblEvidence.Text = ""
        'lblevIDPass.Text = ""
        'lblCustCode.Text = ""
        'lblFistNameTH.Text = ""
        'lblMidNameTH.Text = ""
        'lblLastNameTH.Text = ""
        'lblFistNameEN.Text = ""
        'lblMidNameEN.Text = ""
        'lblLastNameEN.Text = ""

        If Request.QueryString("KYC") = 1 Then
            chkType.Text = Resources.resSearch.DepositIndividual
        ElseIf Request.QueryString("KYC") = 2 Then
            chkType.Text = Resources.resSearch.LoanIndividual
        ElseIf Request.QueryString("KYC") = 3 Then
            chkType.Text = Resources.resSearch.PNIndividual
        ElseIf Request.QueryString("KYC") = 5 Then
            chkType.Text = Resources.resSearch.NPAIndividual
        Else
            chkType.Text = Resources.resSearch.searchAdmin
        End If
        Dim clsDate As New clsDateFormat
        txtStartDate.Text = clsDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)
        txtEndDate.Text = clsDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)



    End Sub

    Sub CreateControlMP()
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/Individual.jpg"

        Dim page As Label = CType(Master.FindControl("lblPage"), Label)
        page.Text = "ค้นหาข้อมูล KYC"
    End Sub

#End Region

#Region " Even Button"

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

        Try

            Me.lblSerch_Result.Text = "" : Me.lblRISK_LEVEL.Text = ""

            clsCheckLanguage = New clsCheckLanguage
            btnAdd.Visible = True
            btnAddOld.Visible = False

            grdIndividual.SelectedIndex = -1
            If ds.Tables.Contains("dsCustomerS") Then
                ds.Tables.Clear()
                grdIndividual.DataSource = Nothing
                grdIndividual.DataBind()
                btnEdit.Visible = False
                btnShow.Visible = False
                btnAdd.Enabled = False
            End If

            ''''validate Date ''''''''''''''''''''''''''''''
            If chkUser.Checked = True Then
                ''''''''''''
                If clsValid.CheckNull(Me.txtStartDate) = False Then Exit Sub

                If (clsValid.CheckDate(txtStartDate) = False) Then
                    Me.txtStartDate.Focus() : Exit Sub
                End If
                '''''''''
                If clsValid.CheckNull(Me.txtEndDate) = False Then Exit Sub
                If (clsValid.CheckDate(txtEndDate) = False) Then
                    Me.txtEndDate.Focus() : Exit Sub
                End If
                '''''''''''
                If DateDiff(DateInterval.Day, CDate(Me.txtEndDate.Text), CDate(Me.txtStartDate.Text)) > 0 Then
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage", "window.alert('ข้อมูลไม่ถูกต้อง ! ช่วงวันที่สลับกัน');", True)
                    Me.txtEndDate.Focus()
                    Exit Sub
                End If
            End If

            ''''validate Date ''''''''''''''''''''''''''''''
            If Not chkUser.Checked = True And Not Request.QueryString("KYC") = 4 Then


                If Me.txtCIF_NO.Text.Trim & txtNo.Text.Trim & Me.txtPASSPORT_NO.Text.Trim & Me.txtOTH_DOC_CARDID.Text <> "" Then
                    If Me.txtFirstNameTH.Text.Trim & _
                        Me.txtMidNameTH.Text.Trim & _
                        Me.txtLastNameTH.Text.Trim & _
                        Me.txtFirstNameEN.Text.Trim & _
                        Me.txtMidNameTH.Text.Trim & _
                        Me.txtLastNameTH.Text.Trim <> "" Then
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertMessage",
                                                            "window.alert('กรุณาป้อนเลขที่บัตรประชาขน/เลขที่หนังสือเดินทาง/เลขที่เอกสารสำคัญอื่น ๆ หรือ ชื่อลูกค้า เพียงเงื่อนไขเดียว');", True)
                        Exit Sub
                    End If


                End If

                If Me.txtCIF_NO.Text.Trim = "" And _
                   Me.txtPASSPORT_NO.Text = "" And _
                   Me.txtOTH_DOC_CARDID.Text = "" And _
                   Me.txtCustCode.Text.Trim = "" And _
                   Me.txtNo.Text.Trim = "" And _
                   Me.txtFirstNameTH.Text.Trim = "" And _
                   Me.txtMidNameTH.Text.Trim = "" And _
                   Me.txtLastNameTH.Text.Trim = "" And _
                   Me.txtFirstNameEN.Text.Trim = "" And _
                   Me.txtMidNameEN.Text.Trim = "" And _
                   Me.txtLastNameEN.Text.Trim = "" Then

                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
                                                        "clientScript",
                                                        "alert('" & Resources.resMsgKYC.msgCondition & "')", True)

                    GoTo checkVisible
                ElseIf txtCustCode.Text.Trim = "*" Or txtNo.Text.Trim = "*" Or txtFirstNameTH.Text.Trim = "*" Or txtMidNameTH.Text.Trim = "*" Or txtLastNameTH.Text.Trim = "*" Or txtFirstNameEN.Text.Trim = "*" Or txtMidNameEN.Text.Trim = "*" Or txtLastNameEN.Text.Trim = "*" Then

                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgCondition & "')", True)

                    GoTo checkVisible
                End If

checkSearch:

                If Not txtNo.Text.Trim = "" And ((Not txtFirstNameTH.Text.Trim = "" Or Not txtMidNameTH.Text.Trim = "" Or Not txtLastNameTH.Text.Trim = "") Or (Not txtFirstNameEN.Text.Trim = "" Or Not txtMidNameEN.Text.Trim = "" Or Not txtLastNameEN.Text.Trim = "")) Then

                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgDoubleCondition & "')", True)
                ElseIf clsCheckLanguage.checkLanguageEN(txtFirstNameEN.Text.Trim, txtMidNameEN.Text.Trim, txtLastNameEN.Text.Trim) = False Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgEN & "')", True)

                    'ElseIf clsCheckLanguage.checkLanguageTH(txtFirstNameTH.Text.Trim, txtMidNameTH.Text.Trim, txtLastNameTH.Text.Trim) = False Then
                    '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgTH & "')", True)
                Else
                    IsDataBind()
                    btnAdd.Enabled = True
                End If
            Else
                GoTo checkSearch
                IsDataBind()
                btnAdd.Enabled = True
            End If

checkVisible:
            VisbleKYC()
            clsCheckLanguage = Nothing
        Catch ex As Exception

            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click

    End Sub

    Protected Sub btnAddOld_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddOld.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex
            If index > -1 Then 'ลูกค้าเก่า - เปิดบัญชีใหม่

                SaveLogSearch(index)

                Response.Redirect("IndividualCDD.aspx?KYC=" & Request.QueryString("KYC") &
                                  "&TypeKYC=2&CUSTSEQ=" &
                                  CInt(grdIndividual.Rows(index).Cells(0).Text) & "")
            Else
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
                                                    "clientScript",
                                                    "alert('" & Resources.resMsgKYC.msgSelect & "')", True)
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnKYC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKYC.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex
            If Request.QueryString("KYC") = 1 Then
                If index = -1 Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),
                                                        "clientScript",
                                                        "window.open('../Form/KYC1T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
                Else
                    SaveLogPrint(index)
                    Dim custtype As String = DirectCast(grdIndividual.Rows(index).FindControl("lblCustCode"), Label).Text
                    If custtype = "ลูกค้าขาจร" Then
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC5T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    Else
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC1T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "&Type=" & Request.QueryString("KYC") & "&KYCSEQ=0','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    End If
                End If
            ElseIf Request.QueryString("KYC") = 2 Then
                If index = -1 Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                        UpdatePanel1.GetType(), "clientScript",
                                                        "window.open('../Form/KYC2T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
                Else
                    SaveLogPrint(index)
                    Dim custtype As String = DirectCast(grdIndividual.Rows(index).FindControl("lblCustCode"), Label).Text
                    If custtype = "ลูกค้าขาจร" Then
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC5T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    Else
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC2T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "&Type=" & Request.QueryString("KYC") & "&KYCSEQ=0','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    End If
                End If
            ElseIf Request.QueryString("KYC") = 3 Then
                If index = -1 Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                        UpdatePanel1.GetType(), "clientScript",
                                                        "window.open('../Form/KYC3T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
                Else
                    SaveLogPrint(index)
                    Dim custtype As String = DirectCast(grdIndividual.Rows(index).FindControl("lblCustCode"), Label).Text
                    If custtype = "ลูกค้าขาจร" Then
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC5T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    Else
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC3T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "&Type=" & Request.QueryString("KYC") & "&KYCSEQ=0','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    End If
                End If
            ElseIf Request.QueryString("KYC") = 5 Then
                If index = -1 Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC4T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
                Else
                    SaveLogPrint(index)
                    Dim custtype As String = DirectCast(grdIndividual.Rows(index).FindControl("lblCustCode"), Label).Text
                    If custtype = "ลูกค้าขาจร" Then
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC5T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    Else
                        ScriptManager.RegisterStartupScript(UpdatePanel1,
                                                            UpdatePanel1.GetType(), "clientScript",
                                                            "window.open('../Form/KYC4T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "','_blank','scrollbars=1,resizable=1,Width:1000px, Height:600px')", True)
                    End If
                End If

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try

            txtCustCode.Text = ""
            txtNo.Text = ""
            txtFirstNameTH.Text = ""
            txtMidNameTH.Text = ""
            txtLastNameTH.Text = ""
            txtFirstNameEN.Text = ""
            txtMidNameEN.Text = ""
            txtLastNameEN.Text = ""
            lblSerch_Result.Text = ""
            Me.lblRISK_LEVEL.Text = ""

            lblMsg.Visible = False

            btnAdd.Enabled = False
            btnAdd.Visible = True
            btnAddOld.Visible = False
            btnShow.Visible = False
            btnEdit.Visible = False

            chkUser.Checked = False

            lblTotal.Text = ""

            If ds.Tables.Contains("dsCustomerS") Then
                ds.Tables("dsCustomerS").Clear()
                grdIndividual.DataSource = ds.Tables("dsCustomerS")
                grdIndividual.DataBind()
                grdIndividual.SelectedIndex = -1
            End If

            VisbleKYC()

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShow.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgSelect & "')", True)
            Else
                If grdIndividual.Rows(index).Cells(8).Text = "&nbsp;" Or grdIndividual.Rows(index).Cells(8).Text = "" Then
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgCDD & "')", True)
                Else
                    Response.Redirect("IndividualKYC.aspx?KYC=" & Request.QueryString("KYC") & "&TypeKYC=4&CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "&CDD=" & CInt(grdIndividual.Rows(index).Cells(8).Text) & "")
                End If
            End If

        Catch ex As Exception

            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnPrintD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintD.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex

            If index = -1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC1T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
            Else

                SaveLogPrint(index)

                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC1T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "&Type=1','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnPrintL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintL.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex

            If index = -1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC2T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
            Else

                SaveLogPrint(index)

                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC2T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnPrintP_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintP.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex

            If index = -1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC1T_01.aspx','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
            Else

                SaveLogPrint(index)

                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('../Form/KYC1T_01.aspx?CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) & "&Type=3 ','_blank','scrollbars=1,resizable=1,Width:800px, Height:600px')", True)
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgSelect & "')", True)
            Else 'ลูกค้าเก่า แก้ไขข้อมูล
                'If grdIndividual.Rows(index).Cells(8).Text = "&nbsp;" Or grdIndividual.Rows(index).Cells(8).Text = "" Then
                '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgCDD & "')", True)
                'Else
                Response.Redirect("IndividualKYC.aspx?KYC=" & Request.QueryString("KYC") &
                                  "&TypeKYC=3&CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) &
                                  "&CDD=" & grdIndividual.Rows(index).Cells(8).Text & "")
                'End If

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

#End Region

#Region " Function"

    Private Sub loadDropDown()
        Try
            clsMasterDropDown = New clsMasterDropDown
            If (clsSessionMenuRight.getRoleGroup > 79) Then
                clsMasterDropDown.setBranchDdlSearch(ddlBranch, strDeptCode:="0", _
                                                strBranchCode:=clsSessionMenuRight.getBranchCode, _
                                                strRoleCode:=clsSessionMenuRight.getRoleGroup, _
                                                strZoneCode:=clsSessionMenuRight.getZoneCode, _
                                                selectData:=clsSessionMenuRight.getBranchCode)

            Else
                clsMasterDropDown.setBranchDdlSearch(ddlBranch, strDeptCode:=clsSessionMenuRight.getDeptCode, _
                                                            strBranchCode:=clsSessionMenuRight.getBranchCode, _
                                                            strRoleCode:=clsSessionMenuRight.getRoleGroup, _
                                                            strZoneCode:=clsSessionMenuRight.getZoneCode, _
                                                            selectData:=clsSessionMenuRight.getBranchCode)

            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Sub VisbleKYC()
        If Request.QueryString("KYC") = 4 Then
            btnEdit.Visible = False
            btnAdd.Visible = False
            btnAddOld.Visible = False
            chkUser.Visible = False

            'btnPrintD.Visible = True
            'btnPrintL.Visible = True
            'btnPrintP.Visible = True

            btnKYC.Visible = False
        Else
            btnShow.Visible = False
        End If
    End Sub

    Private Sub searchAuto(ByVal custSeqttt As Integer)

        Try

            'Dim qryCust = From cust In KYCEntity.MCUSTOMER _
            '          Where cust.CUSTTYPE = 1 And cust.CUSTSEQ = custSeq
            '          Select cust



            ''Dim qryCust = From cust In KYCEntity.MCUSTOMER
            ''              Join past In KYCEntity.MCUST_PASSPORT On cust.CUSTSEQ Equals past.CUSTSEQ
            ''              Join OthD In KYCEntity.MCUST_OTH_DOC On cust.CUSTSEQ Equals OthD.CUSTSEQ
            ''Where (cust.CUSTTYPE = 1 And cust.CUSTSEQ = custSeqttt)
            ''            Select cust.UPDATEDATE,
            ''                   cust.UPDATEBY,
            ''                   cust.CUSTCODE,
            ''                   cust.CUSTSEQ,
            ''                   cust.CUSTTYPE,
            ''                   cust.CUSTSUBTYPE,
            ''                   cust.BRANCHCODE,
            ''                   cust.AMLCDD,
            ''                   cust.AMLCDDOVERVIEW,
            ''                   cust.THFIRSTNAME,
            ''                   cust.THMIDNAME,
            ''                   cust.THLASTNAME,
            ''                   cust.ENPREFIX,
            ''                   cust.ENFIRSTNAME,
            ''                   cust.ENMIDNAME,
            ''                   cust.ENLASTNAME,
            ''                   cust.CUSTIDTYPE,
            ''                   cust.UNIQUEID,
            ''                   past.PASSPORT_NO,
            ''                   OthD.OTH_DOC_CARDID,
            ''                   cust.TRANTYPE,
            ''                   cust.DEPD,
            ''                   cust.DEPL,
            ''                   cust.DEPP,
            ''                   cust.DEPN,
            ''                   cust.DEPUPDATE,
            ''                   cust.NAMESEARCHTH,
            ''                   cust.NAMESEARCHEN,
            ''                   cust.ZONECODE,
            ''                   cust.DEPTCODE,
            ''                   cust.ALLCODERIGHT,
            ''                   cust.ETL_STATUS,
            ''                   cust.CUST_COMPLETE_FLAG,
            ''                   cust.CUSTOMER_OWNER,
            ''                   cust.CIF_CBS_NO,
            ''                   cust.CIF_FDR_NO,
            ''                   cust.CIF_NPA_NO,
            ''                   cust.NEXT_REVIEW

            ''If ds.Tables.Contains("dsCustomerS") Then
            ''    ds.Tables.Remove("dsCustomerS")
            ''End If
            ''ds.Tables.Add(clsDataTable.LINQToDataTable(qryCust, "dsCustomerS").Copy)


            '''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''' Prachak ''''''''''''''''''''''''''''''''''''''''''
            Dim qryCust As String = ""

            qryCust = ""
            qryCust += " SELECT distinct C.updatedate,              "
            qryCust += "        C.updateby,                         "
            qryCust += "        C.CUSTCODE,                         "
            qryCust += "        C.CUSTSEQ AS CUSTSEQ,               "
            qryCust += "        C.CUSTTYPE,                         "
            qryCust += "        C.CUSTSUBTYPE,                      "
            qryCust += "        C.BRANCHCODE,                       "
            qryCust += "        C.AMLCDD,                           "
            qryCust += "        C.AMLCDDOVERVIEW,                   "
            qryCust += "        C.THFIRSTNAME,                      "
            qryCust += "        C.THMIDNAME,                        "
            qryCust += "        C.THLASTNAME,                       "
            qryCust += "        C.ENPREFIX,                         "
            qryCust += "        C.ENFIRSTNAME,                      "
            qryCust += "        C.ENMIDNAME,                        "
            qryCust += "        C.ENLASTNAME,                       "
            qryCust += "        C.CUSTIDTYPE,                       "

            qryCust += "        C.UNIQUEID,                         "
            qryCust += "        D.PASSPORT_NO,                      "
            qryCust += "        E.OTH_DOC_CARDID,                   "

            qryCust += "        C.UPDATEDATE,                       "
            qryCust += "        C.TRANTYPE ,                        "
            qryCust += "        C.DEPD,                             "
            qryCust += "        C.DEPL,                             "
            qryCust += "        C.DEPP,                             "
            qryCust += "        C.DEPN,                             "
            qryCust += "        C.DEPUPDATE,                        "
            qryCust += "        C.NAMESEARCHTH,                     "
            qryCust += "        C.NAMESEARCHEN,                     "
            qryCust += "        C.ZONECODE,                         "
            qryCust += "        C.DEPTCODE,                         "
            qryCust += "        C.ALLCODERIGHT,                     "
            qryCust += "        C.ETL_STATUS,                       "
            qryCust += "        C.CUST_COMPLETE_FLAG,               "
            qryCust += "        C.CUSTOMER_OWNER,                   "
            qryCust += "        C.CIF_CBS_NO,                       "
            qryCust += "        C.CIF_FDR_NO,                       "
            qryCust += "        C.CIF_NPA_NO,                       "
            qryCust += "        C.NEXT_REVIEW                       "
            qryCust += "   FROM MCUSTOMER C,                        "
            qryCust += "        MCUST_PASSPORT D,                   "
            qryCust += "        MCUST_OTH_DOC E                     "
            qryCust += "  WHERE c.CUSTSEQ = d.CUSTSEQ (+)           "
            qryCust += "    AND c.CUSTSEQ = E.CUSTSEQ (+)           "
            qryCust += "    AND c.CUSTTYPE = 1                      "
            qryCust += "    AND c.CUSTSEQ =  '" & custSeqttt & "'   "

            If ds.Tables.Contains("dsCustomerS") Then
                ds.Tables.Remove("dsCustomerS")
            End If
            Dim dt As DataTable = clsDatabase.QueryDataTable(qryCust)
            dt.TableName = "dsCustomerS"
            ds.Tables.Add(dt)
            '''' Prachak ''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''


            ''''''''''''''''''''''''''''''''''''''''''''''''''''''
            grdIndividual.DataSource = ds.Tables("dsCustomerS")
            grdIndividual.DataBind()
            btnAdd.Enabled = True

            If grdIndividual.Rows.Count = 0 Then
                lblMsg.Visible = True
                btnEdit.Visible = False
                btnShow.Visible = False
            Else
                setGrid()
                lblMsg.Visible = False
                btnEdit.Visible = True
                btnShow.Visible = True
            End If

            lblTotal.Text = "จำนวนรายการทั้งหมด " + ds.Tables("dsCustomerS").Rows.Count.ToString + " รายการ "

            clsDataTable = Nothing
        Catch ex As Exception
            WriteError(ex, "SearchAuto", "IndividualSearch")
            Throw ex
        End Try
    End Sub

    Private Sub IsDataBind()


        Dim UserRight As clsSessionMenuRight
        UserRight = Session("clsMenuRight")
        Try

            clsDatabase = New clsDatabase

            'Dim typeOrder As String = "C.CUSTCODE"

            Dim sql As String = ""

            If chkUser.Checked = True Then
                sql = ""
                sql += " SELECT DISTINCT C.updatedate,                  "
                sql += "        C.updateby,                             "
                sql += "        C.CUSTCODE,                             "
                sql += "        C.CUSTSEQ,                              "
                sql += "        C.CUSTTYPE,                             "
                sql += "        C.CUSTSUBTYPE,                          "
                sql += "        C.BRANCHCODE,                           "
                sql += "        C.AMLCDD,                               "
                sql += "        C.AMLCDDOVERVIEW,                       "
                sql += "        C.THFIRSTNAME,                          "
                sql += "        C.THMIDNAME,                            "
                sql += "        C.THLASTNAME,                           "
                sql += "        C.ENPREFIX,                             "
                sql += "        C.ENFIRSTNAME,                          "
                sql += "        C.ENMIDNAME,                            "
                sql += "        C.ENLASTNAME,                           "
                sql += "        C.CUSTIDTYPE,                           "
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += "        C.UNIQUEID,                             "
                sql += "        D.PASSPORT_NO,                          "
                sql += "        E.OTH_DOC_CARDID,                       "
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += "        C.UPDATEDATE,                           "
                sql += "        C.TRANTYPE,                             "
                sql += "        C.DEPD,                                 "
                sql += "        C.DEPL,                                 "
                sql += "        C.DEPP,                                 "
                sql += "        C.DEPN,                                 "
                sql += "        C.DEPUPDATE,                            "
                sql += "        C.NAMESEARCHTH,                         "
                sql += "        C.NAMESEARCHEN,                         "
                sql += "        C.ZONECODE,                             "
                sql += "        C.DEPTCODE,                             "
                sql += "        C.ALLCODERIGHT,                         "
                sql += "        C.ETL_STATUS,                           "
                sql += "        C.CUST_COMPLETE_FLAG,                   "
                sql += "        C.CUSTOMER_OWNER,                       "
                sql += "        C.CIF_CBS_NO,                           "
                sql += "        C.CIF_FDR_NO,                           "
                sql += "        C.CIF_NPA_NO,                           "
                sql += "        C.NEXT_REVIEW                           "

                ''''Prachak '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += "   FROM kycadmin.mcustomer c ,                                  "
                sql += "        kycadmin.log_mcustomer i,                               "
                sql += "        MCUST_PASSPORT D,                                       "
                sql += "        MCUST_OTH_DOC E                                         "
                sql += "  WHERE c.custseq = i.custseq                                   "
                sql += "    AND c.CUSTSEQ = d.CUSTSEQ (+)                               "
                sql += "    AND c.CUSTSEQ = E.CUSTSEQ (+)                               "
                sql += "    AND c.custtype = 1                                          "
                sql += "    AND i.UPDATEBY ='" & clsSessionMenuRight.getUserName & "'   "
                sql += "    AND i.UPDATEDATE >= :StartDate                              "
                sql += "    AND i.UPDATEDATE <= :EndDate                                "
                ''''Prachak '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

                'sql += "   FROM (SELECT DISTINCT updateby,              "
                'sql += "                CUSTSEQ                         "
                'sql += "           FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableLOG_MCUSTOMER") & "  "
                'sql += "          WHERE UPDATEBY ='" & clsSessionMenuRight.getUserName & "'         "
                'sql += "            AND UPDATEDATE >= :StartDate and UPDATEDATE <= :EndDate ) l     "
                'sql += "                LEFT JOIN " & System.Configuration.ConfigurationSettings.AppSettings("TableMCUSTOMER") & " C  "
                'sql += "                       ON l.CUSTSEQ = C.CUSTSEQ       "
                'sql += "                    WHERE c.CUSTTYPE = 1              "

                If Request.QueryString("KYC") = 4 Then
                    If (UserRight.getRoleGroup > 79) Then 'admin ระบบขึ้นไป
                    ElseIf (UserRight.getRoleGroup > 69) Then 'Admin ฝ่าย
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "'"
                    ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "' and C.ZoneCode ='" & UserRight.getZoneCode & "' "
                    ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "' and c.BRANCHCODE='" & UserRight.getBranchCode & "'"
                    ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "' and c.BRANCHCODE='" & UserRight.getBranchCode & "'"
                    End If
                End If

            Else

                '''''Prachak'''
                sql = ""
                sql += " SELECT distinct C.updatedate,      "
                sql += "        C.updateby,                 "
                sql += "        C.CUSTCODE,                 "
                sql += "        C.CUSTSEQ,                  "
                sql += "        C.CUSTTYPE,                 "
                sql += "        C.CUSTSUBTYPE,              "
                sql += "        C.BRANCHCODE,               "
                sql += "        C.AMLCDD,                   "
                sql += "        C.AMLCDDOVERVIEW,           "
                sql += "        C.THFIRSTNAME,              "
                sql += "        C.THMIDNAME,                "
                sql += "        C.THLASTNAME,               "
                sql += "        C.ENPREFIX,                 "
                sql += "        C.ENFIRSTNAME,              "
                sql += "        C.ENMIDNAME,                "
                sql += "        C.ENLASTNAME,               "
                sql += "        C.CUSTIDTYPE,               "

                sql += "        C.UNIQUEID,                             "
                sql += "        D.PASSPORT_NO,                          "
                sql += "        E.OTH_DOC_CARDID,                       "

                sql += "        C.UPDATEDATE,               "
                sql += "        C.TRANTYPE ,                "
                sql += "        C.DEPD,                     "
                sql += "        C.DEPL,                     "
                sql += "        C.DEPP,                     "
                sql += "        C.DEPN,                     "
                sql += "        C.DEPUPDATE,                "
                sql += "        C.NAMESEARCHTH,             "
                sql += "        C.NAMESEARCHEN,             "
                sql += "        C.ZONECODE,                 "
                sql += "        C.DEPTCODE,                 "
                sql += "        C.ALLCODERIGHT,             "
                sql += "        C.ETL_STATUS,               "
                sql += "        C.CUST_COMPLETE_FLAG,       "
                sql += "        C.CUSTOMER_OWNER,           "
                sql += "        C.CIF_CBS_NO,                           "
                sql += "        C.CIF_FDR_NO,                           "
                sql += "        C.CIF_NPA_NO,                           "
                sql += "        C.NEXT_REVIEW               "
                sql += "   FROM " & System.Configuration.ConfigurationSettings.AppSettings("TableMCUSTOMER") & " C,  "
                sql += "        MCUST_PASSPORT D,                                       "
                sql += "        MCUST_OTH_DOC E                                         "
                sql += "  WHERE c.CUSTSEQ = d.CUSTSEQ (+)                               "
                sql += "    AND c.CUSTSEQ = E.CUSTSEQ (+)                               "
                sql += "    AND c.CUSTTYPE = 1                                          "

                If Request.QueryString("KYC") = 4 Then
                    If (UserRight.getRoleGroup > 79) Then 'admin ระบบขึ้นไป
                    ElseIf (UserRight.getRoleGroup > 69) Then 'Admin ฝ่าย
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "'"
                    ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "' and C.ZoneCode ='" & UserRight.getZoneCode & "' "
                    ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "' and c.BRANCHCODE='" & UserRight.getBranchCode & "'"
                    ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
                        sql += " and c.DEPTCODE = '" & UserRight.getDeptCode & "' and c.BRANCHCODE='" & UserRight.getBranchCode & "'"
                    End If
                End If

            End If


            If Not (txtNo.Text.Trim = "") Then
                If (txtNo.Text.Length = 13) Then
                    sql += " and  C.UNIQUEID  = '" & txtNo.Text & "'"
                Else
                    ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                    sql += " and  C.UNIQUEID  like '%" & txtNo.Text.ToUpper.Trim & "%'"
                End If

            End If

            If Not (txtCustCode.Text.Trim = "") Then
                If (txtCustCode.Text.Length = 12) Then
                    sql += " and  C.CUSTCODE = '" & txtCustCode.Text & "'"
                Else
                    sql += " and  C.CUSTCODE  like '" & txtCustCode.Text.ToUpper.Trim.Replace("*", "%") & "'"
                End If

            End If

            If Not (txtFirstNameTH.Text.Trim = "") Then
                ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += " and C.THFIRSTNAME like '%" & txtFirstNameTH.Text.Trim & "%'"
            End If

            If Not (txtMidNameTH.Text.Trim = "") Then
                ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += " and C.THMIDNAME like '%" & txtMidNameTH.Text.Trim & "%'"
            End If

            If Not (txtLastNameTH.Text.Trim = "") Then
                ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += " and C.THLASTNAME like '%" & txtLastNameTH.Text.Trim & "%'"
            End If

            If Not (txtFirstNameEN.Text.Trim = "") Then
                ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += " and UPPER(C.ENFIRSTNAME) like '%" & txtFirstNameEN.Text.ToUpper & "%'"
            End If

            If Not (txtMidNameEN.Text.Trim = "") Then
                ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += " and UPPER(C.ENMIDNAME) like '%" & txtMidNameEN.Text.ToUpper.Trim & "%'"
            End If

            If Not (txtLastNameEN.Text.Trim = "") Then
                ''''Prachak ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                sql += " and UPPER(C.ENLASTNAME) like '%" & txtLastNameEN.Text.ToUpper.Trim & "%'"
            End If

            ''''Prachak ''''CIF_CBS_NO, CIF_FDR_NO, CIF_NPA_NO''''''''''''''''''''''''
            If Not (txtCIF_NO.Text = "") Then
                sql += " and (CIF_CBS_NO like '%" & Me.txtCIF_NO.Text & "%'         "
                sql += "      OR CIF_FDR_NO LIKE '%" & Me.txtCIF_NO.Text & "%'      "
                sql += "      OR CIF_NPA_NO LIKE '%" & Me.txtCIF_NO.Text & "%')     "
            End If
            ''''Prachak '''''''''''''''''''''''''''''
            If Not (txtPASSPORT_NO.Text = "") Then
                sql += " and D.PASSPORT_NO LIKE '%" & Me.txtPASSPORT_NO.Text & "%'"
            End If

            ''''Prachak '''''''''''''''''''''''''''''
            If Not (txtOTH_DOC_CARDID.Text = "") Then
                sql += " and E.OTH_DOC_CARDID LIKE '%" & Me.txtOTH_DOC_CARDID.Text & "%'"
            End If
            If Request.QueryString("KYC") = 4 Then

                sql += " and  C.UPDATEDATE >= :StartDate and C.UPDATEDATE <= :EndDate "

                If Not (ddlBranch.SelectedIndex = 0) Then
                    sql += " and C.BRANCHCODE ='" & ddlBranch.SelectedValue & "' "
                End If

            End If

            Dim cltParameter As Collection = Nothing
            Dim clsVariable As clsVariable = Nothing
            Dim clsDate As New clsDateFormat

            Dim aDate As Date = clsDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strDateIsChk:=txtStartDate.Text)
            Dim bDate As Date = clsDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, strDateIsChk:=txtEndDate.Text)
            cltParameter = New Collection

            clsVariable = New clsVariable
            clsVariable.nameColumn = "StartDate"
            clsVariable.valueColumn = aDate
            cltParameter.Add(clsVariable)

            clsVariable = New clsVariable
            clsVariable.nameColumn = "EndDate"
            clsVariable.valueColumn = bDate
            cltParameter.Add(clsVariable)


            sql += " order by C.THFIRSTNAME"
            'sql += " order by '" & typeOrder & "'"

            If ds.Tables.Contains("dsCustomerS") Then
                ds.Tables.Remove("dsCustomerS")
            End If
            If (chkUser.Checked) Or Request.QueryString("KYC") = 4 Then
                ds.Tables.Add(clsDatabase.QueryDataSet(sql, cltParameter, "dsCustomerS").Tables("dsCustomerS").Copy)

            Else
                ds.Tables.Add(clsDatabase.QueryDataSet(sql, "dsCustomerS").Tables("dsCustomerS").Copy)

            End If


            grdIndividual.DataSource = ds.Tables("dsCustomerS")
            grdIndividual.DataBind()

            cltParameter = Nothing
            clsVariable = Nothing
            clsDate = Nothing


            If grdIndividual.Rows.Count = 0 Then
                lblMsg.Visible = True
                btnEdit.Visible = False
                btnShow.Visible = False
                lblTotal.Text = ""

            Else
                setGrid()
                lblMsg.Visible = False
                btnEdit.Visible = True
                btnShow.Visible = True
                lblTotal.Text = "จำนวนรายการทั้งหมด " + ds.Tables("dsCustomerS").Rows.Count.ToString + " รายการ "

            End If

            clsDataTable = Nothing
            clsDatabase = Nothing
        Catch ex As Exception
            WriteError(ex, "IsDataBind", "IndividualSearch")
            Throw ex
        End Try
    End Sub

    Private Sub setGrid()

        'grdIndividual.HeaderRow.Cells(0).Visible = False
        'grdIndividual.HeaderRow.Cells(8).Visible = False
        'grdIndividual.HeaderRow.Cells(9).Visible = False
        'For i As Integer = 0 To grdIndividual.Rows.Count - 1
        '    grdIndividual.Rows(i).Cells(0).Visible = False
        '    grdIndividual.Rows(i).Cells(8).Visible = False
        '    grdIndividual.Rows(i).Cells(9).Visible = False
        'Next
    End Sub

    Private Sub SaveLogSearch(ByVal index As Integer)
        Try
            Dim program As String = ""
            If Request.QueryString("KYC") = 1 Then
                program = "M11"
            ElseIf Request.QueryString("KYC") = 2 Then
                program = "M21"
            ElseIf Request.QueryString("KYC") = 3 Then
                program = "M31"
            Else
                program = "M41"
            End If


            Dim desc As String = ""

            If chkUser.Checked = True Then
                desc += " ข้อมูลที่ปรับปรุงโดยผู้ใช้งาน "
            End If

            If Not (txtNo.Text.Trim = "") Then
                desc += " หมายเลขบัตร - " + txtNo.Text
            End If

            If Not (txtCustCode.Text.Trim = "") Then
                desc += " เลขประจำตัวลูกค้า - " + txtCustCode.Text
            End If

            If Not (txtFirstNameTH.Text.Trim = "") Then
                desc += " ชื่อลูกค้า (ไทย) - " + txtFirstNameTH.Text
            End If

            If Not (txtMidNameTH.Text.Trim = "") Then
                desc += " ชื่อกลาง (ไทย) - " + txtMidNameTH.Text
            End If

            If Not (txtLastNameTH.Text.Trim = "") Then
                desc += " นามสกุล (ไทย) - " + txtLastNameTH.Text
            End If

            If Not (txtFirstNameEN.Text.Trim = "") Then
                desc += " ชื่อลูกค้า (อังกฤษ) - " + txtFirstNameEN.Text
            End If

            If Not (txtMidNameEN.Text.Trim = "") Then
                desc += " ชื่อกลาง (อังกฤษ) - " + txtMidNameEN.Text
            End If

            If Not (txtLastNameEN.Text.Trim = "") Then
                desc += " นามสกุล (อังกฤษ) - " + txtLastNameEN.Text
            End If

            If Not desc = "" Then
                desc = "ค้นหาข้อมูลจาก " + desc
            End If

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(grdIndividual.Rows(index).Cells(3).Text, clsSessionMenuRight.getUserName, 1, desc, program)
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogPrint(ByVal index As Integer)
        Try
            Dim program As String = ""
            If Request.QueryString("KYC") = 1 Then
                program = "M11"
            ElseIf Request.QueryString("KYC") = 2 Then
                program = "M21"
            ElseIf Request.QueryString("KYC") = 3 Then
                program = "M31"
            Else
                program = "M41"
            End If

            Dim desc As String = "พิมพ์ฟอร์ม KYC"

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(grdIndividual.Rows(index).Cells(3).Text, clsSessionMenuRight.getUserName, 2, desc, program)
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub



#End Region

#Region "Even GridView"

    Dim intBeforeItemIndex As Integer

    Protected Sub grdIndividual_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdIndividual.PageIndexChanging

        grdIndividual.PageIndex = e.NewPageIndex
        grdIndividual.SelectedIndex = -1
        grdIndividual.DataSource = ds.Tables("dsCustomerS")
        grdIndividual.DataBind()
        setGrid()
    End Sub


    Protected Sub grdIndividual_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdIndividual.RowDataBound

        If (e.Row.RowType.ToString = "DataRow") Then
            Dim lblUpdateDate As Label = CType(e.Row.FindControl("lblUpdateDate"), Label)
            If Not (lblUpdateDate.Text = "") Then
                convertDate = New clsDateFormat
                lblUpdateDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, lblUpdateDate.Text)
                convertDate = Nothing
            End If
        End If

    End Sub

    Protected Sub grdIndividual_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdIndividual.SelectedIndexChanged

        If (grdIndividual.SelectedIndex = intBeforeItemIndex) Then
            grdIndividual.SelectedIndex = -1
            btnAdd.Visible = True
            btnAddOld.Visible = False
        End If

        VisbleKYC()
    End Sub
    Protected Sub grdIndividual_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdIndividual.SelectedIndexChanging
        intBeforeItemIndex = grdIndividual.SelectedIndex
        btnAdd.Visible = False
        btnAddOld.Visible = True
        VisbleKYC()
    End Sub

#End Region



    Protected Sub btnSearchSancList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchSancList.Click

        Try
            Session("chkKYC") = Nothing

            Dim lvsWhatIsThis As DataSet = Session("ds")
            If Not lvsWhatIsThis Is Nothing AndAlso lvsWhatIsThis.Tables("Result").Rows.Count > 0 Then
                lblRISK_LEVEL.Text = "Risk Level = " & Me.hdfLevel.Value
                '''''''''''''''''''''''''''''''''''''''''''
            Else
                lblRISK_LEVEL.Text = 0
            End If

            If Session("Sanction") = Nothing Then
                Me.lblSerch_Result.Text = "ไม่มีรายชื่อใน List"
                lblRISK_LEVEL.Text = "Risk Level = 1"
            Else
                Me.lblSerch_Result.Text = "มีรายชื่อใน List"
            End If

            Session("Sanction") = Nothing


        Catch ex As Exception
            Console.WriteLine("")

        End Try

    End Sub


#Region ""
    Private Function checkBeforeFilter() As Boolean
        Try
            clsCheckLanguage = New clsCheckLanguage
            clsCheckID = New clsCheckID
            Dim result As Boolean = True

            If txtFirstNameTH.Text.Trim = "" And txtLastNameTH.Text.Trim = "" Then
                result = False
            Else
                If clsCheckLanguage.checkLanguageTH(txtFirstNameTH.Text.Trim, txtMidNameTH.Text.Trim, txtLastNameTH.Text.Trim) = False Then
                    result = False
                Else

                End If
            End If


TH:
            If txtFirstNameEN.Text.Trim = "" And txtLastNameEN.Text.Trim = "" Then
                result = False
               
            Else
                If clsCheckLanguage.checkLanguageEN(txtFirstNameEN.Text.Trim, txtMidNameEN.Text.Trim, txtLastNameEN.Text.Trim) = False Then

                    result = False

                Else

                End If
            End If

EN:

            If result = False Then
                statusValidation()
            End If

            clsCheckLanguage = Nothing

            Return result
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub statusValidation()

    End Sub

#End Region

    Protected Sub grdIndividual_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
        Try
            If (e.CommandName = "Acc_Import") Then
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                Dim row As GridViewRow = grdIndividual.Rows(index)

                ' Add code here to add the item to the shopping cart.

                Dim url As String = "IndividualReasonPopup.aspx?KYC=" & Request.QueryString("KYC") &
                                      "&TypeKYC=2&CUSTSEQ=" &
                                      CInt(grdIndividual.Rows(index).Cells(0).Text) & ""

                ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                               UpdatePanel1.GetType(), _
                                                               "clientScript", _
                                                               "OpenReasonPopup('" + url + "')", _
                                                               True)

            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub
    Protected Sub btnShowAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowAccount.Click
        Try

            Dim index As Integer = grdIndividual.SelectedIndex
            If index = -1 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgSelect & "')", True)
            Else
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "OpenAccountPopup('IndividualAccountPopup.aspx?KYC=" & Request.QueryString("KYC") &
                                  "&TypeKYC=3&CUSTSEQ=" & CInt(grdIndividual.Rows(index).Cells(0).Text) &
                                  "&CDD=" & grdIndividual.Rows(index).Cells(8).Text & "')", True)
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub
End Class

